package me.leiusual.sharing.api

import com.google.gson.JsonObject
import io.reactivex.Single
import me.leiusual.sharing.api.model.*
import me.leiusual.sharing.api.model.businesscondition.BusinessCondition
import me.leiusual.sharing.api.model.cartdetail.CartList
import me.leiusual.sharing.api.model.orderconfirm.OrderConfirm
import me.leiusual.sharing.api.model.orderdetail.OrderDetail
import me.leiusual.sharing.api.model.orderlist.OrderList
import me.leiusual.sharing.api.model.productsearch.ProductSearch
import me.leiusual.sharing.api.model.storeindex.StoreIndex
import me.leiusual.sharing.api.model.storeproductquery.StoreProductQuery
import me.leiusual.sharing.api.model.storesearch.StoreSearch
import me.leiusual.sharing.api.model.userrenew.UserRenew
import me.leiusual.sharing.api.model.usertotal.UserTotal
import retrofit2.http.*

/**
 * Create by leiusual on 2018/7/16
 */
interface ApiSharing {

  companion object {
    const val BASE_URL = "https://www.lingling9.com"
  }

  @POST("/api/ad/start")
  fun adStart(@Body params: AdStart.Request): Single<List<AdStart.Response>>

  @POST("/api/qr")
  fun inviteQRCode(@Body params: InviteQRCode.Request): Single<InviteQRCode.Response>

  @POST("/api/user/invited")
  fun invited(@Body params: Invited.Request): Single<Invited.Response>

  @GET("/api/store/apply")
  fun storeApply(@Query("n") n: String): Single<Unit>

  @GET("/api/storesearch")
  fun storeSearch(@Query("p") p: Int,
                  @Query("ps") ps: Int,
                  @Query("q") q: String): Single<StoreSearch>

  @POST("/api/store/categories")
  fun storeCategories(@Body params: StoreCategories.Request): Single<StoreCategories.Response>

  @POST("/api/store/detail")
  fun storeDetail(@Body params: StoreDetail.Request): Single<StoreDetail.Response>

  @GET("/api/store/index")
  fun storeIndex(@Query("bsid") bsid: Long,
                 @Query("sid") sid: Long): Single<StoreIndex>

  @POST("/api/store/product/query")
  fun storeProductQuery(@Body params: StoreProductQuery.Request): Single<StoreProductQuery.Response>

  @GET("/api/search")
  fun productSearch(@Query("p") p: Int,
                    @Query("ps") ps: Int,
                    @Query("q") q: String,
                    @Query("storeId") storeId: Long): Single<ProductSearch>

  @GET("/api/product/detail")
  fun productDetail(@Query("aid") aId: Long?,
                    @Query("mid") mid: Long,
                    @Query("r") r: Long?): Single<ProductDetail>

  @POST("/api/cart/add")
  fun cartAdd(@Query("mia") mia: Long,
              @Query("quantity") quantity: Int,
              @Query("r") r: Long?): Single<Unit>

  @POST("/api/cart/change")
  fun cartChange(@Query("shopCartId") shopCartId: Long,
                 @Query("quantity") quantity: Int): Single<Unit>

  @GET("/api/cart/list")
  fun cartList(): Single<CartList>

  @POST("/api/cart/remove")
  fun cartRemove(@Query("shopCartId") shopCartId: Long): Single<Unit>

  @GET("/api/address/{userId}")
  fun address(@Path("userId") userId: Long): Single<List<Address>>

  @GET("/api/address/delete/{aId}")
  fun addressDelete(@Path("aId") aId: Long): Single<Unit>

  @GET("/api/address/list")
  fun addressList(): Single<List<Address>>

  @GET("/api/address/region/query")
  fun addressRegionQuery(@Query("k") k: String,
                         @Query("p") p: Int = -2): Single<Map<Long, String>>

  @GET("/api/address/sms/{phone}")
  fun addressSms(@Path("phone") phone: String): Single<Unit>

  @POST("/api/address/update")
  fun addressUpdate(@Body address: Address): Single<Unit>

  @POST("/api/order/check")
  fun orderCheck(@Body map: Map<Long, Int>): Single<Unit>

  @POST("/api/order/confirm")
  fun orderConfirm(@Body map: Map<Long, Int>): Single<OrderConfirm>

  @FormUrlEncoded
  @POST("/api/order/checkout")
  fun orderCheckout(@Query("addressId") addressId: Long,
                    @Query("openid") openId: String,
                    @Query("payType") payType: String,
                    @Query("storeCarts") storeCarts: String,
                    @FieldMap other: Map<String, String>): Single<JsonObject>

  @GET("/api/order/list")
  fun orderList(@Query("p") p: Int,
                @Query("ps") ps: Int,
                @Query("q") q: String,
                @Query("s") s: Int): Single<OrderList>

  @GET("/api/store/{storeId}/order")
  fun orderList(@Path("storeId") storeId: Long,
                @Query("p") p: Int,
                @Query("ps") ps: Int,
                @Query("q") q: String,
                @Query("s") s: Int): Single<OrderList>

  @GET("api/order/{code}")
  fun orderDetail(@Path("code") code: String): Single<OrderDetail>

  @GET("api/store/{storeId}/order/{code}")
  fun orderDetail(@Path("storeId") storeId: Long,
                  @Path("code") code: String): Single<OrderDetail>

  @POST("/api/order/repay/{code}")
  fun orderRePay(@Path("code") code: String): Single<JsonObject>

  @POST("/api/order/{code}/delete")
  fun orderDelete(@Path("code") code: String): Single<Unit>

  @POST("/api/order/{code}/confirm")
  fun orderConfirm(@Path("code") code: String): Single<Unit>

  @GET("/api/logistics")
  fun orderLogistics(@Query("num") number: String,
                     @Query("type") type: String): Single<String>

  @GET("/api/bank/accounttype")
  fun bankAccountType(): Single<Map<String, String>>

  @GET("/api/bank/delete/{baId}")
  fun bankDelete(@Path("baId") baId: Long): Single<Unit>

  @GET("/api/bank/list")
  fun bankList(): Single<List<Bank>>

  @POST("/api/bank/update")
  fun bankUpdate(@Body bank: Bank): Single<Unit>

  @GET("/api/business/apply")
  fun businessApply(): Single<List<BusinessType>>

  @GET("/api/business/apply/{strBuType}")
  fun businessApply(@Path("strBuType") strBuType: String): Single<List<BusinessLevel>>

  @GET("/api/business/apply/{strBusinessType}/{strBusinessLevel}")
  fun businessApply(@Path("strBusinessType") strBusinessType: String,
                    @Path("strBusinessLevel") strBusinessLevel: String): Single<BusinessCondition>

  @POST("/api/business/apply")
  fun businessApply(@Body params: BusinessApply.Request): Single<List<BusinessApply.Response>>

  @GET("/api/withdraw/account")
  fun withdrawAccount(): Single<Map<String, String>>

  @POST("/api/withdraw/create")
  fun withdrawCreate(@Body request: WithdrawCreate.Request): Single<Unit>

  @GET("/api/withdraw/apply/{wcId}")
  fun withdrawApply(@Path("wcId") wcId: Long): Single<Unit>

  @GET("/api/withdraw/delete/{wcId}") // 正常应该是cancel 目前就用删除
  fun withdrawCancel(@Path("wcId") wcId: Long): Single<Unit>

  @GET("/api/withdraw/delete/{wcId}")
  fun withdrawDelete(@Path("wcId") wcId: Long): Single<Unit>

  @GET("/api/withdraw/query")
  fun withdrawQuery(@Query("pi") pi: Int,
                    @Query("ps") ps: Int,
                    @Query("sid") sid: Long): Single<List<Withdraw>>

  @GET("/api/user/total")
  fun userTotal(): Single<UserTotal>

  @GET("api/usermessage/query")
  fun userMessageQuery(@Query("pi") pi: Int,
                       @Query("ps") ps: Int): Single<List<UserMessage>>

  @GET("api/usermessage/view/{id}")
  fun userMessageView(@Path("id") id: Long): Single<Unit>

  @GET("/api/useraccount/list/{type}") // store 、user
  fun userAccountList(@Path("type") type: String): Single<List<UserAccount>>

  @GET("/api/useraccount/detail")
  fun userAccountDetail(@Query("id") id: Long,
                        @Query("pi") pi: Int,
                        @Query("ps") ps: Int): Single<List<UserAccountLog>>

  @GET("/api/user/renew/list")
  fun userRenewList(@Query("b") b: String?,
                    @Query("u") u: Long): Single<UserRenew>
}